package com.guohengspace.mq.controller;


import com.guohengspace.mq.common.ResponseResult;
import com.guohengspace.mq.model.query.CompleteMultipartUploadParam;
import com.guohengspace.mq.model.query.DescribeImagesParam;
import com.guohengspace.mq.model.query.ImportImageParam;
import com.guohengspace.mq.model.query.UpLoadPartParam;
import com.guohengspace.mq.service.EcsImportImageService;
import com.guohengspace.mq.service.OssUploadPartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "测试创建")
@RequestMapping("/test")
public class TestController {

    @Autowired
    OssUploadPartService ossUploadPartService ;

    @Autowired
    EcsImportImageService ecsImportImageService ;
    @Operation(tags = "镜像管理", summary = "全局镜像id分片查看", description = "全局镜像id分片查看")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accessKeyId", value = "组织ak", dataType = "String", paramType = "query", example = "1111",required = true),
            @ApiImplicitParam(name = "accessKeySecret", value = "组织sk", dataType = "String", paramType = "query", example = "1222",required = true),
            @ApiImplicitParam(name = "uploadId", value = "全局id", dataType = "String", paramType = "query", example = "1111.qcow2",required = true)
    })
    public ResponseResult<?> listpartsrequest(String accessKeyId, String accessKeySecret, String uploadId) {
        return ResponseResult.ok(ossUploadPartService.listpartsrequest(uploadId,accessKeyId,accessKeySecret));
    }

    @Operation(tags = "镜像管理", summary = "查看ak、sk listBuckets ", description = "查看ak、sk listBuckets ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accessKeyId", value = "组织ak", dataType = "String", paramType = "query", example = "1111",required = true),
            @ApiImplicitParam(name = "accessKeySecret", value = "组织sk", dataType = "String", paramType = "query", example = "1222",required = true),
    })
    public ResponseResult<?> listBuckets(String accessKeyId, String accessKeySecret) {
        return ResponseResult.ok(ossUploadPartService.listBuckets(accessKeyId,accessKeySecret));
    }

    @Operation(tags = "镜像管理", summary = "合并分片", description = "分片上传完成，合并分片")
    @PostMapping("/completemultipartupload")
    public ResponseResult<?> completeMultipartUpload(CompleteMultipartUploadParam completeMultipartUploadParam) {
        return ResponseResult.ok(ossUploadPartService.completeMultipartUpload(completeMultipartUploadParam));
    }

    @Operation(tags = "镜像管理", summary = "生成全局镜像id", description = "生成全局镜像id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accessKeyId", value = "组织ak", dataType = "String", paramType = "query", example = "1111",required = true),
            @ApiImplicitParam(name = "accessKeySecret", value = "组织sk", dataType = "String", paramType = "query", example = "1222",required = true),
            @ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "String", paramType = "query", example = "1111.qcow2",required = true)
    })
    public ResponseResult<?> initiateMultipartUpload(String accessKeyId, String accessKeySecret, String fileName) {
        return ResponseResult.ok(ossUploadPartService.initiateMultipartUpload(accessKeyId,accessKeySecret,fileName));
    }

    @Operation(tags = "镜像管理", summary = "分片上传", description = "分片上传")
    @PostMapping("/uploadpart")
    public ResponseResult<?> uploadpart(@RequestBody UpLoadPartParam upLoadPartParam) {
        return ossUploadPartService.upLoadPart(upLoadPartParam);
    }

    @Operation(tags = "镜像管理", summary = "ecs上传oss镜像文件", description = "ecs上传oss镜像文件")
    @GetMapping("/import")
    public ResponseResult<?> importImage(ImportImageParam importImageParam) {
        return ecsImportImageService.importImage(importImageParam);
    }

    @Operation(tags = "镜像管理", summary = "ecs查询镜像文件", description = "ecs上传oss镜像文件")
    @GetMapping("/describeImages")
    public ResponseResult<?> describeImages(DescribeImagesParam param) {
        return ResponseResult.ok(ecsImportImageService.describeImages(param));
    }

}
